<?php
include 'config.php';
ini_set('date.timezone','Asia/Shanghai');//调整时区
$hdid1=$config['hdid1'];//活动名称
$hdid2=$config['hdid2'];//活动名称
$time=$config['time'];//时间

/*连接数据库*/
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "data";

$conn = new mysqli($servername, $username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}
//按10分钟统计某个活动的图片量
$sql="SELECT * , COUNT( * ) AS count, SUBSTRING(  `date` , 1, 15 ) AS dateindex FROM msg WHERE mtype =3 and (hdid = '$hdid1'or hdid = '$hdid2')GROUP BY SUBSTRING(  `date` , 1, 15 ) HAVING  SUBSTRING(  `date` , 1, 10 )='$time'";
$result = $conn->query($sql);//查询到的结果集
$data1=array();//放置查询的数据
if ($result->num_rows > 0) {
    // 输出每行数据
    $row = $result->fetch_assoc();
    $count=1;//给定一个初始值
    $date=date("H:i",strtotime( $row['dateindex'].'0'));//补全date，按10分钟为单位
    while($row = $result->fetch_assoc()) {
        $f=floor((strtotime(date("H:i",strtotime( $row['dateindex'].'0')))-strtotime(date("H:i",strtotime($date))))%86400/600);//计算中间是不是差了
        $data['date']=date("H:i",strtotime( $row['dateindex'].'0'));//补全date，按10分钟为单位
        $data['count']=$row['count'];//按10分钟统计得到的值
        $data1[]=$data;
        $dd=$date;
        $date=$row['dateindex'].'0';
        if($f>1){//计算中间差了几分钟
            while(--$f){
                $data['count']=0;
                $data['date'] =date('H:i',strtotime("$dd+10minute"));//补全中间差的零
                $data1[] = $data;
                $dd=$data['date'];//倒换下
            }
        }
    }
} else{
    echo "没有数据";
}
echo json_encode($data1);
$conn->close();

?>